#include	"SubWinCode.hpp"

SubWinCode::SubWinCode(unsigned int heightWinCode, unsigned int widthWinCode, WINDOW *winCode, unsigned int widthSubWinWarning, unsigned int widthSubWinLines)
{
  this->_height = heightWinCode - 2;
  this->_width = widthWinCode - 5 - 7 - 2;
  this->_win = derwin(winCode, this->_height, this->_width, 1, 1 + widthSubWinWarning + widthSubWinLines);
  box(this->_win, 0, 0);
  wrefresh(this->_win);
}

SubWinCode::~SubWinCode()
{
  
}

void	SubWinCode::setContentWin(const char *name_file)
{
  //open / read File source code
  this->_fileTree = new ContentFile(name_file);
  
  //open file source code
  this->_scrollText = new ScrollText(this->_fileTree->getList(), this->_height, this->_width, this->_win);
}

void	SubWinCode::checkEvent(int event)
{
  if (event == KEY_DOWN)
    this->_scrollText->cursorDown();
  else if (event == KEY_UP)
    this->_scrollText->cursorUp();
}

void	SubWinCode::update(bool focus)
{
  if (focus)
    enableColorPair1(this->_win);
  box(this->_win, 0, 0);
  if (focus)
    disableColorPair1(this->_win);
  this->_scrollText->update();
}

ContentFile	*SubWinCode::getContentTree()const
{
  return (this->_fileTree);
}

ScrollText	*SubWinCode::getScrollText()const
{
  return (this->_scrollText);
}
